<template>
  <el-table :data="filterTableData" style="width: 100%" size="defalut">
    <el-table-column label="序号" prop="disid" />
    <el-table-column label="病人姓名" prop="patientname" />
    <el-table-column label="预约时间" prop="disbooktime" />
    <el-table-column prop="patientid" label="身份证号码" :formatter="hideidNumber">
    </el-table-column>
    <el-table-column align="right">
      <template #header>
        <el-input v-model="search" size="default" placeholder="Type to search" />
      </template>
      <!-- @click="handleDelete(scope.$index)" -->
      <template #default="scope">
        <el-button size="default" type="primary" @click="Diagnosis(scope.row)">点击诊断</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script lang="ts" setup>
import { computed, ref } from "vue";
import { useRouter } from "vue-router";
import { onMounted } from "vue";
// import axios from "axios";
import user from "@/store";
import service from "@/request";
const search = ref('')
interface User {
  num: number
  name: string
  sex: string
  id:string
}
onMounted(() => {
  getAppointments();
});

const filterTableData = computed(() =>
  data.value.filter(
    (data) =>
      !search.value ||
      data.patientname.toLowerCase().includes(search.value.toLowerCase())
  )
)
var data = ref([])
const getAppointments = async () => {
  console.log(user.state.user.loginUser)
  console.log("获取数据");
  try {
    const response = await service.post("/Diagnosis/getBookDiagnosis",
      {
        doctorName : user.state.user.loginUser.userName,
      }
    );
    data.value = response.data;
    console.log(response.data);
  } catch (error) {
    console.error("获取预约信息失败：", error);
  }
};
const hideidNumber = (row, column, cellValue) => { return cellValue.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2'); }

const router = useRouter()
// 诊断
const Diagnosis = (row) => {
  console.log(row.name);
  router.push(
    {
      path: '../doctor/treatMent',
      query: {
        name: row.patientname,
        id: row.patientid,
      },
    });

}
</script>
